package com.mzy.datepackage.M2022.Apr.six;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author mzy
 * @Date 2022/4/9 10:37
 * @Version 1.0
 */
public class Demo4 {
    public static void main(String[] args) throws Exception {
        byte[] b = { 20 , 10 , 30 , 5 };


        saveFile("TEST2.txt",b);
    }


    public static void saveFile(String filename,byte [] data)throws Exception{
        try {
            if(data != null){
    //            String filepath ="D:\\" + filename;
                File file  = new File(filename);
                if(file.exists()){
                    file.delete();
                }
                FileOutputStream fos = new FileOutputStream(file);
                fos.write(data,0,data.length);
                fos.flush();
                fos.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
